package com.xxl.job.executor.service.patrol;

import com.web.all.common.bean.response.Result;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.executor.mvc.api.AppPatrolApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



/**
 * 执行专项巡查规则任务
 * @author lc
 */
@JobHandler(value="SpecialPatrolTaskJobHandler")
@Component
public class SpecialPatrolTaskJobHandler extends IJobHandler {
    private static final Logger log = LoggerFactory.getLogger(SpecialPatrolTaskJobHandler.class);

    private final AppPatrolApi appPatrolApi;

    @Autowired
    public SpecialPatrolTaskJobHandler(AppPatrolApi appPatrolApi) {
        this.appPatrolApi = appPatrolApi;
    }

    @Override
    public ReturnT<String> execute(String param){
        XxlJobLogger.log("SpecialPatrolTaskJobHandler, 创建任务. 参数{}",param);
        log.info("SpecialPatrolTaskJobHandler, 创建任务. 参数{}",param);
        try{
            Result result = appPatrolApi.send(param);
            if(result.isSuccess()){
                XxlJobLogger.log("SpecialPatrolTaskJobHandler, 创建任务成功. 参数{}",param);
                log.info("SpecialPatrolTaskJobHandler, 创建任务成功. 参数{}",param);
                return SUCCESS;
            }
            XxlJobLogger.log("SpecialPatrolTaskJobHandler, 创建任务失败. 参数{}",param);
            log.error("SpecialPatrolTaskJobHandler, 创建任务失败. 参数:{}，原因：{}",param,result.getMsg());
            return FAIL;
        }catch (Exception e){
            log.error("SpecialPatrolTaskJobHandler, 创建任务失败. 参数{}，原因：{}",param,e.getMessage());
            return FAIL;
        }
    }

}
